package com.hnust.api;

import com.hnust.domain.*;
import feign.Response;
import feign.codec.Encoder;
import feign.form.spring.SpringFormEncoder;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.support.SpringEncoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;


@FeignClient(
        name = "subjectApis",
        url = "${feign.baseUrl}",
        configuration = SubjectApis.MultipartSupportConfig.class
)
public interface SubjectApis {
    @GetMapping("/download/question")
    Response getTem();

    //获取老师的所有课程
    @GetMapping("/api/subject/getCourseData")
    Result<List<CourseData>> getCourseData(@RequestParam("id") String id);

    //删除题目
    @GetMapping("/api/subject/delCourseSub")
    Result<Boolean> delCourseSub(@RequestParam("subject_id") String subject_id,
                                 @RequestParam("id") String id);

    @PostMapping(value="/upload/v2/questions",
            headers = {"Content-Type="+MediaType.MULTIPART_FORM_DATA_VALUE})
    Result<List<BulkImport>> upload(@RequestPart("file") MultipartFile file,
                                    @RequestParam("courseId") String courseId);

    //使其支持实体类和文件上传的参数
    @Configuration
    class MultipartSupportConfig {
        @Autowired
        private ObjectFactory<HttpMessageConverters> messageConverters;
        @Bean
        public Encoder feignFormEncoder() {
            return new SpringFormEncoder(new SpringEncoder(messageConverters));
        }
    }

    //修改题目信息 subjectData,token,id
    @PostMapping(value = "/api/subject/updateSubInfo",headers = {"Content-Type="+MediaType.APPLICATION_JSON_VALUE})
    Result<String> updateSubInfo(@RequestBody SubjectDataReq subjectDataReq);

    //上传到数据库
    @PostMapping(value="/api/subject/addSub",headers = {"Content-Type="+MediaType.APPLICATION_JSON_VALUE})
    Result<Boolean> addSub(@RequestBody SubjectDataListReq subjectDataListReqs);

    @GetMapping("/api/subject/getCourseSubByCon")
    Result<List<SubjectTest>> getCourseSub(@RequestParam("course_id")String courseId,@RequestParam("id")String id,
                                           @RequestParam("currentPage")Integer currentPage,
                                           @RequestParam("rows")Integer rows,@RequestParam("keyword")String keyword);

    @GetMapping("/api/subject/getCourseTargetList")
    Result<List<CourseTargetRecord>> getCourseTargetRecord(@RequestParam("course_id")String courseId,
                                                           @RequestParam("id")String id);

    @GetMapping("/api/subject/getCourseChapterList")
    Result<List<CourseChapter>> getCourseChapterList(@RequestParam("course_id")String course_id,
                                                           @RequestParam("id") String id);
    @GetMapping("/api/teacher/testpaper/getQuesTypeList")
    Result<List<QuestionTypeRecord>> getQuesTypeList(@RequestParam("id") String id);
}
